/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-12-10     Administrator       the first version
 */
#ifndef APPLICATIONS_DEVICE_DEVMANAGER_H_
#define APPLICATIONS_DEVICE_DEVMANAGER_H_

#include <rtdef.h>

#ifdef __cplusplus
extern "C" {
#endif

#define TOTAL_DEV_NUM       200
#define TOTAL_MOTOR_NUM     30
enum
{
RESERVE = 0,
MOTOR = 1,
IO = 2,
SENSOR = 3,
DELAY = 4,
};

typedef struct DEV_MANAGER
{
    uint8_t dev_num;
    char dev_name[10];
    uint8_t board_addr;
    uint8_t devType;
    uint8_t dirver_num;
}DEV_MANAGER;

const DEV_MANAGER dev_info[TOTAL_DEV_NUM] = {
//D0 is a demo.
{0,         "DELAY",      1,      52,      1   },
//dev_num dev_name board_num devType dirver_num
{1,         "ARM_X",      1,      MOTOR,     1   },
{2,         "ARM_Y",      1,      MOTOR,     2   },
{3,         "ARM_Z",      1,      MOTOR,     3   },
{4,         "ARM_P",      1,      MOTOR,     4   },
{5,           "WP1",      1,      IO,        1   },
{6,           "WP2",      1,      IO,        2   },
{7,           "WP3",      1,      IO,        3   },
{8,           "WP1",      1,      IO,        4   },
{9,           "WP2",      1,      IO,        5   },
{10,          "WP3",      1,      IO,        6   },
{11,          "WP1",      1,      IO,        7   },
{12,          "WP2",      1,      IO,        8   },
{13,          "WP1",      1,      SENSOR,    1   },
{14,          "WP2",      1,      SENSOR,    2   },
{15,      "RESERVE",      RESERVE,RESERVE,RESERVE},
{16,      "RESERVE",      RESERVE,RESERVE,RESERVE},
{17,      "RESERVE",      RESERVE,RESERVE,RESERVE},
{18,      "RESERVE",      RESERVE,RESERVE,RESERVE},
{19,      "RESERVE",      RESERVE,RESERVE,RESERVE},
{20,      "RESERVE",      RESERVE,RESERVE,RESERVE},
{21,      "RESERVE",      RESERVE,RESERVE,RESERVE},
{22,      "RESERVE",      RESERVE,RESERVE,RESERVE},
{23,      "RESERVE",      RESERVE,RESERVE,RESERVE},
{24,      "RESERVE",      RESERVE,RESERVE,RESERVE},
{15,      "RESERVE",      RESERVE,RESERVE,RESERVE},
};



typedef struct MOTOR_MANAGER
{
    uint8_t dev_num;
    uint8_t positive_direction;
    uint8_t circle_optimize;
    uint16_t fine_fraction;
    uint32_t step_per_revolution;
    uint8_t cs;
}MOTOR_MANAGER;

enum
{
  CW,
  ACW
};


const MOTOR_MANAGER motor_info[TOTAL_MOTOR_NUM] = {
{0,     CW,     true,     256,    200 , 31},
//demo
{1,     CW,     true,     256,    200 , 31},
{2,     CW,     true,     256,    200 , 31},
{3,     CW,     true,     256,    200 , 31},
{4,     CW,     true,     256,    200 , 31},
{5,     CW,     true,     256,    200 , 31},
{6,     CW,     true,     256,    200 , 31},


};


typedef struct MOTOR_SPD
{
uint32_t vstart;
uint32_t a1;
uint32_t v1;
uint32_t amax;
uint32_t vmax;
uint32_t dmax;
uint32_t d1;
uint32_t vstop;
}MOTOR_SPD;


uint8_t QueryOfDevBoardNum(int dev_num);
uint8_t QueryOfDevType(int dev_num);
uint8_t MyBoardDev(int dev_num);
uint8_t QueryOfDevDriverNum(int dev_num);
uint8_t QueryOfDevCircleOptimize(int dev_num);
uint8_t QueryOfDevFineFraction(int dev_num);
uint32_t QueryOfDevStepPerRevolution(int dev_num);
uint32_t QueryOfDevUStepPerRevolution(int dev_num);

uint32_t position_model_calculator(uint8_t dev_num,uint8_t position_dot);
uint32_t position_scaler(uint8_t dev_num,uint8_t position_dot);

#ifdef __cplusplus
}
#endif


#endif /* APPLICATIONS_DEVICE_DEVMANAGER_H_ */
